package com.hongxun.project.assets.b10kvLineInfo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hongxun.framework.aspectj.lang.annotation.Log;
import com.hongxun.framework.aspectj.lang.enums.BusinessType;
import com.hongxun.project.assets.b10kvLineInfo.domain.B10kvLineInfo;
import com.hongxun.project.assets.b10kvLineInfo.service.IB10kvLineInfoService;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.framework.web.domain.AjaxResult;
import com.hongxun.common.utils.poi.ExcelUtil;

/**
 * 10kv线路 信息操作处理
 * 
 * @author hongxun
 * @date 2019-03-19
 */
@Controller
@RequestMapping("/assets/b10kvLineInfo")
public class B10kvLineInfoController extends BaseController
{
    private String prefix = "assets/b10kvLineInfo";
	
	@Autowired
	private IB10kvLineInfoService b10kvLineInfoService;
	
	@RequiresPermissions("assets:b10kvLineInfo:view")
	@GetMapping()
	public String b10kvLineInfo()
	{
	    return prefix + "/b10kvLineInfo";
	}

	/**
	 * 上级线路选择列表
	 * @return
	 */
	@GetMapping("/choose10kvLine")
	public String choose10kvLine()
	{
		return prefix + "/choose10kvLine";
	}

	/**
	 * 上级线路名称回显
	 * @param map
	 * @return
	 */
	@PostMapping("/getLineName")
	@ResponseBody
	public Map<String , Object> getLineName(@RequestParam Map<String, Object> map)
	{
		Map<String , Object> newMap = new HashMap<>();
		List<B10kvLineInfo> b10kvLineInfo = b10kvLineInfoService.selectB10kvLineInfoList(new B10kvLineInfo());
		newMap.put("b10kvLineInfo", b10kvLineInfo);
		return newMap;
	}


	/**
	 * 查询10kv线路列表
	 */
//	@RequiresPermissions("assets:b10kvLineInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(B10kvLineInfo b10kvLineInfo)
	{
		startPage();
        List<B10kvLineInfo> list = b10kvLineInfoService.selectB10kvLineInfoList(b10kvLineInfo);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出10kv线路列表
	 */
	@RequiresPermissions("assets:b10kvLineInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(B10kvLineInfo b10kvLineInfo)
    {
    	List<B10kvLineInfo> list = b10kvLineInfoService.selectB10kvLineInfoList(b10kvLineInfo);
        ExcelUtil<B10kvLineInfo> util = new ExcelUtil<B10kvLineInfo>(B10kvLineInfo.class);
        return util.exportExcel(list, "b10kvLineInfo");
    }
	
	/**
	 * 新增10kv线路
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存10kv线路
	 */
	@RequiresPermissions("assets:b10kvLineInfo:add")
	@Log(title = "10kv线路", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(B10kvLineInfo b10kvLineInfo)
	{		
		return toAjax(b10kvLineInfoService.insertB10kvLineInfo(b10kvLineInfo));
	}

	/**
	 * 修改10kv线路
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		B10kvLineInfo b10kvLineInfo = b10kvLineInfoService.selectB10kvLineInfoById(id);
		mmap.put("b10kvLineInfo", b10kvLineInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存10kv线路
	 */
	@RequiresPermissions("assets:b10kvLineInfo:edit")
	@Log(title = "10kv线路", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(B10kvLineInfo b10kvLineInfo)
	{		
		return toAjax(b10kvLineInfoService.updateB10kvLineInfo(b10kvLineInfo));
	}
	
	/**
	 * 删除10kv线路
	 */
	@RequiresPermissions("assets:b10kvLineInfo:remove")
	@Log(title = "10kv线路", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(b10kvLineInfoService.deleteB10kvLineInfoByIds(ids));
	}
	
}
